package com.excuse.excusebuilder.view.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.afollestad.materialdialogs.MaterialDialog;
import com.bumptech.glide.Glide;
import com.excuse.excusebuilder.R;
import com.excuse.excusebuilder.base.BaseFragment;
import com.excuse.excusebuilder.bean.User;
import com.excuse.excusebuilder.view.activity.MineDetailActivity;
import com.excuse.excusebuilder.view.activity.SignInActivity;

import butterknife.BindView;
import butterknife.OnClick;
import cn.bmob.v3.BmobUser;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by U-nookia on 2017/4/14.
 */

public class MineFragment extends BaseFragment {
    public static final int POST = 1;
    public static final int COMMENT = 2;
    public static final int FEEDBACK = 3;

    @BindView(R.id.mine_head)
    CircleImageView mineHead;
    @BindView(R.id.mine_name)
    TextView mineName;
    @BindView(R.id.mine_top)
    RelativeLayout mineTop;
    @BindView(R.id.post)
    RelativeLayout post;
    /*@BindView(R.id.like)
    RelativeLayout like;*/
    @BindView(R.id.comment)
    RelativeLayout comment;
    @BindView(R.id.feedback)
    RelativeLayout feedback;
    @BindView(R.id.about)
    RelativeLayout about;

    @Override
    protected void initData() {
        mineName.setText(BmobUser.getCurrentUser().getUsername());
        Glide.with(getContext()).load(BmobUser.getCurrentUser(User.class).getAvatarUrl()).into(mineHead);
    }

    @Override
    public int getFragmentLayout() {
        return R.layout.fragment_mine;
    }

    @OnClick({R.id.mine_top, R.id.post, R.id.comment, R.id.feedback, R.id.about})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.mine_top:
                new MaterialDialog.Builder(getContext())
                        .items(R.array.dialog)
                        .itemsCallback(new MaterialDialog.ListCallback() {
                            @Override
                            public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) {
                                BmobUser.logOut();
                                startActivity(new Intent(getContext(), SignInActivity.class));
                                finish();
                            }
                        }).build().show();
                break;
            case R.id.post:
                Bundle bundle = new Bundle();
                bundle.putInt("item",POST);
                MineDetailActivity.jumpToDetailActivity(getContext(),bundle);
                break;
            /*case R.id.like:
                break;*/
            case R.id.comment:
                Bundle bundle1 = new Bundle();
                bundle1.putInt("item",COMMENT);
                MineDetailActivity.jumpToDetailActivity(getContext(),bundle1);
                break;
            case R.id.feedback:
                Bundle bundle2 = new Bundle();
                bundle2.putInt("item",FEEDBACK);
                MineDetailActivity.jumpToDetailActivity(getContext(),bundle2);
                break;
            case R.id.about:
                break;
        }
    }

    @Override
    public void finish() {
        getActivity().finish();
    }
}
